{template 'weheader'}
<style>
.weui_cells_tips {margin-top: .3em;padding-left: 0;padding-right: 0;}
.page-bd .weui-flex {padding: 0px;}
.weui_input{padding-left:5px;}
.weui_label{font-size:14px;}
</style>
<div class="weui_msg" id="weui_msg">
	<div class="weui_media_hd" style="margin:0 auto;">
		<img class="circle" src="{$member['avatar']}" style="height:80px;">
	</div>
	<div class="weui_cells_tips">
	<form id="form" class="form-horizontal" method="post" role="form">
        <input class="weui_input" type="hidden" name="avatar" id="avatar" value="{$member['avatar']}" />
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd">
					<svg class="icon" aria-hidden="true">
						<use xlink:href="#icon-member"></use>
					</svg>
				</div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" name="realname" id="realname" value="{$member['realname']}" placeholder="请输入您的姓名"/>
                </div>
            </div>
            <div class="weui_cell">
				<div class="weui_cell_hd">
					<svg class="icon" aria-hidden="true">
						<use xlink:href="#icon-phone"></use>
					</svg>
				</div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="tel" name="mobile" id="mobile" value="{$member['mobile']}" required pattern="[0-9]{11}" maxlength="11" placeholder="请输入手机号码" emptyTips="请输入手机号" notMatchTips="请输入正确的手机号">
                </div>
            </div>
			<div class="weui_cell">
				<div class="weui_cell_hd">
					<svg class="icon" aria-hidden="true">
						<use xlink:href="#icon-display"></use>
					</svg>
				</div>
				<div class="weui_cell_bd weui_cell_primary">
					<input type="hidden" id="htel">
					<input type="hidden" id="hsms">
					<input class="weui_input" id="sms" name="sms" type="tel"  placeholder="请输入手机验证码">
				</div>
				<div class="weui_cell_ft">
				<input type="button" id="sendsms" class="weui_btn weui_btn_mini bg-blue" value="获取验证码">
				</div>
			</div>
		</div>
        <div class="weui_opr_area">
            <p class="weui_btn_area">
				<a class="weui_btn weui_btn_primary" style="width:100%;" id="formSubmitBtn">保存</a>
            </p>
        </div>
	</form>
	</div>
</div>

<script type="text/javascript">

var returnurl = '{$_GPC['returnurl']}';
var wait=60;
var mobile = $("#mobile").val();
function time(o) {
	if (wait == 0) {
		o.removeAttribute("disabled");
		o.value="获取验证码";
		wait = 60;
	} else {
		o.setAttribute("disabled", true);
		o.value="重新发送(" + wait + ")";
		wait--;  
		setTimeout(function() {
			time(o)
		}, 1000)
	}
}
	$("#sendsms").bind("click",function(){
		var mobile = $('#mobile').val();
		var checktel = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
			if($.trim($(':input[name="mobile"]').val())=='' || !checktel.test($.trim($('input[name="mobile"]').val()))){
				$('#mobile').val(""); 
				$.toptips("请输入正确的手机号码", "warning");
				return false;
			}else{
				$.post("{php echo $this->createMobileUrl('SendSms', array('id' => $id, 'openid' => $openid, 'form' => $_GPC['form']));}", {'mobile':mobile},function(data){
					if(data.message.state == 1) {
						$("#htel").val(data.message.mobile);
						$("#hsms").val(data.message.yzm);
						$.toast(data.message.msg, "success");
					}else{
						$.toast(data.message.msg, "cancel");
					}
				},"json");
				time(this);
			}
	});

$("#formSubmitBtn").on("click", function(){
	var realname = $('#realname').val(),
		mobile = $('#mobile').val(),
		checktel = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	if (!mobile) {
		$.toast("请填写手机号码！", "cancel");
		return false;
	}
	if($.trim($(':input[name="mobile"]').val())=='' || !checktel.test($.trim($('input[name="mobile"]').val()))){
		$('#mobile').val(""); 
		$.toptips("请输入正确的手机号码", "warning");
		return false;
	}
	if (!realname) {
		$.toast("请填写姓名！", "cancel");
		return false;
	}
	var htel=$("#htel").val(),
		hsms=$("#hsms").val(),
		tel=$("#mobile").val(),
		sms=$("#sms").val();
	if(htel==tel){
		if(hsms==sms){
		}else{
			$.toast("请输入正确验证码", "cancel");
			return false;
		}
	}else{
		$.toast("请获取验证码", "cancel");
		return false;
	}
	var submitData = {
		'realname':realname,
		'mobile':mobile
	};
	$.post('{php echo $this->createMobileUrl('index', array('op' => 'post'));}', submitData, function (data){
		if (data.message.status == 1) {
			$.toast(data.message.msg, "success");
			setTimeout(function() {
				window.location.href = decodeURIComponent(returnurl);
				return;
			}, 1000)
			return;
		} else {
			$.toast(data.message.msg, "cancel");
			setTimeout(function() {
				window.location.href = decodeURIComponent(returnurl);
				return;
			}, 1000)
		}
	},"json");
});
</script>
{template 'footers'}